package com.itwk.gulimall.product.web;

import com.itwk.gulimall.product.entity.PmsCategoryEntity;
import com.itwk.gulimall.product.service.PmsCategoryService;
import com.itwk.gulimall.product.vo.webVo.Catalog2List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: wangke
 * @Date: 2021/01/27/上午 11:56
 * @Description:
 */
@Controller
public class WebIndexController {
    @Autowired
    private PmsCategoryService categoryService;
    @GetMapping({"/","/index"})  //转发请求到首页
    public String webIndex(Model model){
//        public static final String DEFAULT_PREFIX = "classpath:/templates/";
//        public static final String DEFAULT_SUFFIX = ".html";
      List<PmsCategoryEntity> categoryEntities =  categoryService.getLevel1();
      model.addAttribute("categoryEntities",categoryEntities);
        return "index";
    }



    @GetMapping("/index/catalog.json")   //查询返回分类数据，前端渲染
    @ResponseBody //需要返回json 格式
    public Map<String,List<Catalog2List>>  getCatalog2List(){

        Map<String,List<Catalog2List>> catalog2List  = categoryService.getCatalog2List();

          return catalog2List;
    }
}
